第二部分：页面加载和数据提取(Person
2)
# person2_code.py
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


def load_page_and_get_html(driver, question_url):
    """
    加载知乎问题页面并返回HTML内容
    :param driver: WebDriver实例
    :param question_url: 知乎问题的URL
    :return: 页面HTML内容
    """
    print(f"开始使用 Selenium 爬取：{question_url}")

    driver.get(question_url)

    # 等待页面加载完成
    WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, 'div.List-item'))
    )

    return driver.page_source


def parse_answer_item(answer_item):
    """
    解析单个回答项，提取作者、内容、点赞数和评论数
    :param answer_item: BeautifulSoup对象，表示单个回答
    :return: 包含回答信息的字典
    """
    content_div = answer_item.find('div', class_='RichContent-inner')
    content = content_div.get_text(separator='\n', strip=True) if content_div else ""

    author_tag = answer_item.find('a', class_='UserLink-link')
    author = author_tag.get_text(strip=True) if author_tag else "匿名用户"

    voteup_count_tag = answer_item.find('button', class_='VoteButton--up')
    voteup_count = 0
    if voteup_count_tag:
        voters_span = voteup_count_tag.find('span', class_='Voters')
        if voters_span:
            try:
                voteup_count = int(
                    voters_span.get_text(strip=True).replace(' 赞同', '').replace('K', '000').replace('万',
                                                                                                      '0000'))
            except ValueError:
                pass

    comment_count_tag = answer_item.find('button',
                                         class_='Button ContentItem-action Button--plain Button--withIcon Button--withLabel',
                                         text=lambda t: '评论' in t if t else False)
    comment_count = 0
    if comment_count_tag:
        try:
            comment_count_text